package com.sitanyun.merchant.guide.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sitanyun.merchant.guide.R;
import com.sitanyun.merchant.guide.bean.SwishShopBean;

import java.util.List;

/**
 * Created by jzl
 * on 2022/1/7.
 * 切换门店适配器
 */
public class SwichsAdapter extends BaseAdapter {
private Context context;
private List<SwishShopBean.DataBean>  data;
    private int positions = -1;//用于记录当前位置
    public SwichsAdapter(Context context, List<SwishShopBean.DataBean> data) {
        this.context = context;
        this.data = data;
    }
    /*
     * 用于设置当前位置
     */
    public  void setPosition(int position) {
        this.positions = position;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView=  LayoutInflater.from(context).inflate(R.layout.swishop_item,null);
       TextView swishop= convertView.findViewById(R.id.swi_shop);
        TextView xz=  convertView.findViewById(R.id.xz);
        TextView  swiadress= convertView.findViewById(R.id.swi_address);
        TextView  swizy= convertView.findViewById(R.id.swi_zy);
        TextView swienter = convertView.findViewById(R.id.swi_enter);
        swishop.setText(data.get(position).getStoreName());

        if (positions==-1){
            if (data.get(position).getIsClick().equals("1")){
                xz.setVisibility(View.VISIBLE);
            }else {
                xz.setVisibility(View.GONE);
            }
        }else {
            //       //选择
        if (positions == position) {
            xz.setVisibility(View.VISIBLE);
        } else {
            xz.setVisibility(View.GONE);
        }
        }


        swiadress.setText(data.get(position).getAddress());
        swizy.setText(data.get(position).getPosition());
        swienter.setText(data.get(position).getEnterpriseName());
        return convertView;
    }
}
